import Vue from 'vue'
import Router from 'vue-router'

import Index from '@/components/Index'
import Jxkt from './jxkt';
import Mall from './mall';
import My from './my';


// 额外引入的路由，全部放到数组中
let router_arr = [Jxkt, Mall, My];

// 合并数组中的路由
const concatRoute = (router_arr) => {

    let router = [];

    router_arr.map(routers => {

        routers.map(router_obj => {
            router.push(router_obj);
        });
    });

    return router;
}
// 定义首页路由
let route_base = [{ path: '/', name: 'index', meta: { title: '可莎生活馆' }, component: Index }];

// 其他文件中合并的路由
let route_others = concatRoute(router_arr);

// 路由合并
let routes = route_base.concat(route_others);

Vue.use(Router)

var router = new Router({
    // mode: 'history',
	scrollBehavior: () => ({
		y: 0
	}), // 滚动条的滚动行为，不加这个默认会记忆原来滚动条的位置
    routes: routes
});


/**
 * 路由跳转前操作
 * to		即将进入的目标路由对象
 * from		当前导航正要离开的路由
 * next		next()			进行下一个钩子
 * 			next(false)		中断导航，跳到from路由
 * 			next('/')		跳转到/路由
 */
router.beforeEach((to, from, next) => {
    next();
});

/**
 *
 * 路由跳转后操作
 *
 */
router.afterEach((transition) => {

});

export default router;
